package cn.springcloud.test;
import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * lambda表达式
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Person {
    private Integer id ;
    private String name ;
    private List<hobbitEnum> hobbit;
    @Getter
    enum hobbitEnum{
        SING(1,"唱歌"),
        DANCING(2,"跳舞"),
        READING(3,"看书"),
        Listen(4,"听歌");
        int value ;
        String name ;
        hobbitEnum(int value ,String name) {
            this.value = value ;
            this.name = name ;
        }
    }
    public static void main(String[] args) {
        //小红猫
        List<hobbitEnum> hobbit1 = new ArrayList<hobbitEnum>();
        hobbit1.add(hobbitEnum.SING);
        Person p1 = new Person(1,"小红猫",hobbit1);
        //小红
        List<hobbitEnum> hobbit2 = new ArrayList<hobbitEnum>();
        hobbit2.add(hobbitEnum.DANCING);
        hobbit2.add(hobbitEnum.SING);
        Person p2 = new Person(2,"小红",hobbit2);
        //小明
        List<hobbitEnum> hobbit3 = new ArrayList<hobbitEnum>();
        hobbit3.add(hobbitEnum.DANCING);
        Person p3 = new Person(3,"小明",hobbit3);
        List<Person> personList = new ArrayList<Person>();
        personList.add(p1);
        personList.add(p2);
        personList.add(p3);

        //将符合条件的过滤出来  这得到的是一个 person
//       personList.stream().filter(person -> person.getName().startsWith("小红"))
//                          .filter(person -> {
//                              Optional<hobbitEnum> any = person.getHobbit().parallelStream().filter(h -> h.getName().equals("唱歌")).findAny();
//                              return any.isPresent();
//                          })
//                          .forEach(System.out::println);

       //排序
        List<Person> collect = personList.stream().sorted((o1, o2) -> o2.getName().compareTo(o1.getName())).collect(Collectors.toList());
        collect.stream().forEach(System.out::println);


    }
}
